﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using DataAccessLayer;

namespace BussinessLogicLayer
{
    public class Service
    {
        private static TinChiEntitiesDataContext _tinChiDataContext;

        public static TinChiEntitiesDataContext TinChiDataContext
        {
            get
            {   if(_tinChiDataContext == null)
                {
                    if (!Ketnoi()) return null;
                }
                return _tinChiDataContext;
            }
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        public static bool Ketnoi()
        {
            {
                try
                {
                    if (_tinChiDataContext == null)
                    {
                        _tinChiDataContext = new TinChiEntitiesDataContext();
                    }
                    return true;
                }
                catch (Exception)
                {
                    _tinChiDataContext.Dispose();
                    return false;
                }
            }
        }

    }
}
